import React from 'react';
import { Route, Routes, Navigate } from 'react-router-dom';
import Login from '../pages/Login';
import Layout from '../pages/Layout';
const Home = React.lazy(() => import('../pages/Home/index'));
const Dashboard = React.lazy(() => import('../pages/content/Dashboard'));
const Settings = React.lazy(() => import('../pages/content/Settings'));

const AppRoutes = () => {
  return (
    <Routes>
        <Route path="/login" element={<Login />} />
        <Route path="/" element={<Layout />}>
          {/* 进入根路径时重定向到 home */}
          <Route index element={<Navigate to="home" replace />} />
          <Route path="home" element={<React.Suspense fallback={<>加载中...</>}><Home /></React.Suspense>} />
          <Route path="dashboard" element={<React.Suspense fallback={<>加载中...</>}><Dashboard /></React.Suspense>} />
          <Route path="settings" element={<React.Suspense fallback={<>加载中...</>}><Settings /></React.Suspense>} />
        </Route>
        {/* 处理未知路径 */}
        <Route path="*" element={<Navigate to="/" replace />} />
      </Routes>
  );
};

export default AppRoutes;